package com.egao.texasHoldEmPoker.service.impl;

import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.JsonResult;
import com.egao.common.system.entity.User;
//import com.egao.texasHoldEmPoker.mapper.PlayerMapper;
import com.egao.texasHoldEmPoker.entity.Player;
import com.egao.texasHoldEmPoker.service.PlayerService;
import org.springframework.stereotype.Service;
import com.egao.texasHoldEmPoker.biz.PlayerBiz;
import net.sf.json.JSONObject;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
//import javax.transaction.Transactional;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 玩家服务实现类
 * @author : Doman
 * @date : 2022-01-26 12:39:41
 * @version ：1.0
 */
@Service
public class PlayerServiceImpl /*extends ServiceImpl<PlayerMapper, Player> */implements PlayerService {

	@Autowired
	private PlayerBiz playerBiz;

    /**
    @Override
    public PageResult<Player> listPage(PageParam<Player> page) {
        List<Player> records = baseMapper.listPage(page);
        return new PageResult<>(records, page.getTotal());
    }

    @Override
    public List<Player> listAll(Map<String, Object> page) {
        return baseMapper.listAll(page);
    } */

    @Override
    public JsonResult list(PageResult2<T> page, Player player, User loginUser)  throws Exception{
        return playerBiz.list(page,player,loginUser);
    }

    @Override
    public JsonResult list(Player player, User loginUser) {
        return JsonResult.ok().setData(playerBiz.list(player,loginUser));
    }

    @Override
    public JsonResult getById(Player player) {
        return JsonResult.ok().setData(playerBiz.getById(player));
    }

    @Transactional
    @Override
    public JsonResult save(Player player, User loginUser) {
        if (playerBiz.save(player, loginUser)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }

    @Transactional
    @Override
    public JsonResult update(Player player, User loginUser) {
        if (playerBiz.update(player, loginUser)) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }

    @Transactional
    @Override
    public JsonResult remove(Player player, User loginUser) {
        if (playerBiz.remove(player, loginUser)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }

}
